﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace TresselLS
{
    public partial class CallDisplayForm : Form
    {
        public CallDisplayForm(string[] memArray, int lowestAddress, int highestAddress,int locationCounter, string oAC, string oIR, string oBR, string oSTAT, string nAC, string nIR, string nBR, string nSTAT)
        {
            /*!
            Procedure Name: CallDisplayForm
            Description: sets the register labels to their proper values and displays the memory array
            Input Parameters: ArrayList memArray, string oAC, string oIR, string oBR, string oSTAT, string nAC, string nIR, string nBR, string nSTAT
            Output Parameters: none
            Errors Conditions Tested:
            Error Messages Generated:
            Original Author: Steve Rudy
            Procedure Creation Date: 11/24/2009
            Modification Log:
            Who: Steve Rudy
            When: 11/25/2009
            Why: need to show location counter
            Who: Steve Rudy
            When: 11/29/2009
            Why: memArray parameter is of type string[] instead of ArrayList
            Who: Steve Rudy
            When: 11/30/2009
            Why: we should only display active memory locations, not all memory locations
            Coding standards met: SR
            Testing standards met: RM
            !*/
            InitializeComponent();
            oACLabel.Text = oAC;
            oBRLabel.Text = oBR;
            oIRLabel.Text = oIR;
            oSTATLabel.Text = oSTAT;
            nACLabel.Text = nAC;
            nBRLabel.Text = nBR;
            nIRLabel.Text = nIR;
            nSTATLabel.Text = nSTAT;
            this.locationCounterLabel.Text = Converter.ToHex(locationCounter);
            /*#
            Variable Name: rowCount
            Module Where Defined: CallDisplayForm
            Data Type: int
            Local or Global: Local
            Purpose: determines the number of rows to be shown in order for all memory to be displayed
            #*/
            int rowCount = Convert.ToInt32(Math.Ceiling((decimal)(highestAddress-lowestAddress+1) / 8));
            /*#
            Variable Name: addr
            Module Where Defined: CallDisplayForm
            Data Type: int
            Local or Global: Local
            Purpose: the counter that iterates through the memory array
            #*/
            int addr = lowestAddress;
            for (int i = 0; i < rowCount; i++)
            {
                /*#
                Variable Name: newRow
                Module Where Defined: CallDisplayForm
                Data Type: string[]
                Local or Global: Local
                Purpose: holds the values for the row to be displayed
                #*/
                string[] newRow = new string[8];
                for (int j = 0; j < 8; j++)
                {
                    if (highestAddress >= addr)
                    {
                        newRow[j] = memArray[addr].ToString();
                    }
                    else
                    {
                        newRow[j] = "";
                    }
                    addr++;
                }
                memoryDataGridView.Rows.Add(newRow);
                memoryDataGridView.Rows[memoryDataGridView.Rows.Count - 1].HeaderCell.Value = (addr - 8).ToString() + " - " + (addr - 1).ToString();
            }
        }

        private void continueButtonClick(object sender, EventArgs e)
        {
            /*!
            Procedure Name: continueButtonClick
            Description: closes the form when the user clicks the "Continue" button
            Input Parameters: object sender, EventArgs e
            Output Parameters: none
            Errors Conditions Tested:
            Error Messages Generated:
            Original Author: Steve Rudy
            Procedure Creation Date: 11/24/2009
            Modification Log:
            Coding standards met: SR
            Testing standards met: RM
            !*/
            this.Close();
        }
    }
}
